<template>
  <div>
    <el-dialog title="新增或修改" :visible.sync="dialogVisible" width="400px">
      <el-form class="demo-form-inline" :inline="true" label-width="100px">
        <el-form-item :label="purviewNameType" required>
          <el-input v-model="data.purviewName" />
        </el-form-item>

        <el-form-item label="权限编码(“_role_”开头)" v-if="data.purviewType==2">
          <el-input v-model="data.purviewCode" />
        </el-form-item>

        <el-form-item label="菜单地址" required>
          <el-input v-model="data.purviewUrl" />
        </el-form-item>

        <el-form-item label="禁/启用" required>
          <el-select v-model="data.isUse" placeholder="请选择">
            <el-option
              v-for="item in isUseList"
              :label="item.isUse"
              :value="item.value"
              :key="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="菜单图标">
          <el-input v-model="data.icon" />
        </el-form-item>

        <el-form-item label="排序" v-if="data.purviewId">
          <el-input v-model="data.orderNumber" />
        </el-form-item>

        <el-form-item label="备注">
          <el-input v-model="data.remark" />
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit()">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import apisystemmenu from "@/api/baseManager/systemmenu";
export default {
  name: "dialogEditMenu",
  components: {},
  data() {
    return {
      dialogVisible: false,
      purviewNameType: "菜单名称",
      data: this.clearData(),
      isUseList: apisystemmenu.isUseList
    };
  },
  methods: {
    clearData() {
      return {
        purviewId: "",
        purviewName: "", //菜单/权限名称
        orderNumber: "", //排序
        purviewCode: "", //权限编码(“_role_”开头)
        icon: "", //菜单图标
        remark: "", //备注
        purviewUrl: "", //菜单ur
        parentId: "", //父id
        purviewType: 1, //菜单类型
        isUse:1,
      };
    },
    //编辑
    openedit(flag, row) {
      this.data = this.clearData();
      this.dialogVisible = true;
      if (flag == "addLevelOneMenu") {
        //新增一级菜单
        this.data.parentId = "first";
        this.data.level = 1;
      } else if (flag == "addOtherMenu") {
        //新增其他菜单
        this.data.parentId = row.purviewId;
        this.data.level = row.nextLevel;
      } else {
        //修改菜单
        apisystemmenu.getOneItouchSysPurview({ purviewId: row.purviewId }).then(res => {
            this.data = res.data.dto;
            this.data.level = row.level;
          });
      }
    },

    //提交
    submit() {
      apisystemmenu.saveOrUpdatePurview(this.data).then(res => {
        this.dialogVisible = false;
        if (this.data.level == 1) {
          this.$parent.getList();
        } else if (this.data.level == 2) {
          if (this.data.purviewId) {
            this.$parent.twomenu({ purviewId: this.data.parentId });
          } else {
            this.$parent.twomenu({
              purviewId: this.data.purviewId || this.data.parentId
            });
          }
        } else {
          if (this.data.purviewId) {
            this.$parent.threemenu({ purviewId: this.data.parentId });
          } else {
            this.$parent.threemenu({
              purviewId: this.data.purviewId || this.data.parentId
            });
          }
        }
      });
    }
  }
};
</script>

<style scoped>
</style>